package com.smartEdu.service.impl.app;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.smartEdu.commons.CMap;
import com.smartEdu.commons.LogCvt;
import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.dao.ChapterDao;
import com.smartEdu.dao.CourseCommentDao;
import com.smartEdu.exception.JsonException;
import com.smartEdu.exception.ServiceException;
import com.smartEdu.model.CourseCommentModel;
import com.smartEdu.model.HomeWorkModel2;
import com.smartEdu.service.CourseCommentService;

@Service(value="courseCommentServiceImpl")
public class CourseCommentServiceImpl extends BaseServiceImpl implements CourseCommentService{

	
	@Autowired
	@Qualifier(value="courseCommentDaoImpl")
    private	CourseCommentDao courseCommentDao;
	@Override
	public void getCourseCommentServiceByPk(Session sess) {
		// TODO Auto-generated method stub
		List<CourseCommentModel> models=null;
		CMap map=null;
		try {
			map=SetToMap(sess);
			//数据有限，暂时写死
//			models=courseCommentDao.getCourseCommentByPk(map.gets("pk"));
			String pk="AF3442FSAFA";
			models=courseCommentDao.getCourseCommentByPk(pk);
			sess.put("comment", models);
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.OK);
		}
		catch (JsonException e){
			LogCvt.error(Tag_Tips.JSONERROR,e);
			throw new ServiceException("json出错");
		}
		catch (Exception e) {
			LogCvt.error(e.getMessage(),e);
			throw new ServiceException("业务流程出错");
		}
		finally {
			map=null;
		}
		
	}
	@Override
	public void addCourseComment(Session sess) {
		// TODO Auto-generated method stub
		CMap map=null;
		map=SetToMap(sess);
	    System.out.print(map.gets("cname"));
		try {
		
			CourseCommentModel model=new CourseCommentModel();
			model.setCname(map.gets("cname"));
			model.setPk(map.gets("pk"));
			model.setCtime(map.geti("time"));
			model.setContent(map.gets("content"));
			model.setPraisenum(0);
			model.setUrl(map.gets("url"));
			courseCommentDao.addCourseComment(model);
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.OK);
		}
		catch (JsonException e){
			LogCvt.error(Tag_Tips.JSONERROR,e);
			throw new ServiceException("json出错");
		}
		catch (Exception e) {
			LogCvt.error(e.getMessage(),e);
			throw new ServiceException("业务流程出错");
		}
		finally {
			map=null;
		}
		
		
	}

}
